import fnmatch
import os


# 识别图片集合 suffix:后缀匹配*.sql,可用正则
def get_files_from_path(directory, suffix):
    for filename in os.listdir(directory):
        if fnmatch.fnmatch(filename.lower(), suffix):
            yield os.path.join(directory, filename)


# 获取文件内容
def getContent(path):
    content = ''
    # 打开文件，指定编码为utf-8
    with open(path, 'r', encoding='utf-8') as file:
        # 读取文件内容
        content = file.read()
    return content


# 脚本入口点
if __name__ == "__main__":
    # 结果文件名
    target = '1.sql'
    path = "./"

    result = []
    for file_path in get_files_from_path(path, "*.sql"):
        result.append(getContent(file_path))
    # 将数组写入指定文件
    with open(target, 'w', newline='', encoding='utf-8') as file:
        for row in result:
            print(row)
            file.write(row)
    print("结束")
